

//
//  HEVideoCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/15.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEVideoCell.h"

@interface HEVideoCell ()
 
@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *titleLb;

@property (strong, nonatomic) QMUIFillButton *startBtn;

@end

@implementation HEVideoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI {
    UIView *warp = [UIView new];
    [self.contentView addSubview:warp];

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(0);
        make.right.equalTo(self.contentView).mas_offset(0);
        make.bottom.equalTo(self.contentView).mas_offset(0);
    }];
    
    // 头像
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];
    

    // 姓名
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYBlodFont(17);
    _titleLb.numberOfLines = 2;
    [warp addSubview:_titleLb];
    
    
    _startBtn = [[QMUIFillButton alloc] initWithFillType:QMUIFillButtonColorBlue];
    _startBtn.titleLabel.font = DYFont(14);
    [_startBtn setBackgroundColor:CNavBgColor];
    [_startBtn setTitle:@"开始学习" forState:UIControlStateNormal];
    [warp addSubview:_startBtn];
    [_startBtn addTarget:self action:@selector(toStartStudyClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(15);
        make.left.equalTo(warp).mas_offset(15);
        make.width.height.mas_offset(100);
        make.bottom.equalTo(warp).mas_offset(-10);
    }];
    [_goodsimgView hg_setAllCornerWithCornerRadius: 5];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsimgView.mas_top);
        make.left.equalTo(_goodsimgView.mas_right).mas_offset(11);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

    [_startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_goodsimgView.mas_bottom).mas_offset(-10);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.width.mas_greaterThanOrEqualTo(80);
        make.height.mas_greaterThanOrEqualTo(29);
    }];
}
 
- (void)setModel:(HEVideoListModel *)model {
    _model = model;
    
    _titleLb.text = model.title;
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.video_icon] placeholderImage:IMAGE_NAMED(@"noImage")];
}

- (void)toStartStudyClick {
    if ([_delegate respondsToSelector:@selector(toVideoPage:)]) {
        [_delegate toVideoPage:_model];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
